﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MarcatelHD.Models;

namespace MarcatelHD.Controllers
{ 
    public class ServiciosController : Controller
    {
        private marcateldbEntities db = new marcateldbEntities();

        //
        // GET: /Servicios/
        [Authorize(Roles = "Administrador")]
        public ViewResult Index()
        {
            return View(db.tblServicios.ToList());
        }

        //
        // GET: /Servicios/Details/5
        [Authorize(Roles = "Administrador")]
        public ViewResult Details(int id)
        {
            tblServicios tblservicios = db.tblServicios.Find(id);
            return View(tblservicios);
        }

        //
        // GET: /Servicios/Create
        [Authorize(Roles = "Administrador")]
        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Servicios/Create
        [Authorize(Roles = "Administrador")]
        [HttpPost]
        public ActionResult Create(tblServicios tblservicios)
        {
            if (ModelState.IsValid)
            {
                db.tblServicios.Add(tblservicios);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(tblservicios);
        }
        
        //
        // GET: /Servicios/Edit/5
 [Authorize(Roles = "Administrador")]
        public ActionResult Edit(int id)
        {
            tblServicios tblservicios = db.tblServicios.Find(id);
            return View(tblservicios);
        }

        //
        // POST: /Servicios/Edit/5
        [Authorize(Roles = "Administrador")]
        [HttpPost]
        public ActionResult Edit(tblServicios tblservicios)
        {
            if (ModelState.IsValid)
            {
                db.Entry(tblservicios).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(tblservicios);
        }

        //
        // GET: /Servicios/Delete/5
 [Authorize(Roles = "Administrador")]
        public ActionResult Delete(int id)
        {
            tblServicios tblservicios = db.tblServicios.Find(id);
            return View(tblservicios);
        }

        //
        // POST: /Servicios/Delete/5
        [Authorize(Roles = "Administrador")]
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            tblServicios tblservicios = db.tblServicios.Find(id);
            db.tblServicios.Remove(tblservicios);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}